--
-- Author:      feilong
-- DateTime:    2019-10-23 17:19:33
-- Description: 管理服务, 节点间消息的处理


require "skynet.manager"
local skynet = require "skynet"
local NodeMessage = require "NodeMessage"
local MessageDispatch = require "MessageDispatch"
local MessageHandler = require "manager.MessageHandler"

local AssignManager = require "AssignManager"
local GameManager = require "GameManager"

local ClusterManager = require("ClusterManager")
local ServerManager = require("ServerManager")
local ServerInfo = require("ServerInfo")
local UserManager = require("UserManager")

global = {}

local function init()
	local message_dispatch = MessageDispatch.new()	
	local node_message = NodeMessage.new()
	local message_handler = MessageHandler.new(message_dispatch)
	local assign_manager = AssignManager.new()
	local game_manager = GameManager.new()

	local cluster_manager = ClusterManager.new(message_dispatch)
	local server_manager = ServerManager.new()
	local server_info = ServerInfo.new() --节点相关信息
	local user_manager = UserManager.new()	

	global.message_dispatch = message_dispatch
	global.node_message = node_message
	global.message_handler = message_handler
	global.assign_manager = assign_manager
	global.game_manager = game_manager

	global.cluster_manager = cluster_manager
	global.server_info = server_info
	global.server_manager = server_manager
	global.user_manager = user_manager
	--开启集群节点
	global.cluster_manager:open(server_info)
	skynet.dispatch("lua", message_dispatch:dispatch())	
end


---------------------------------------------------------
-- skynet
---------------------------------------------------------


skynet.start(function()
	init()
	skynet.register('.manager')
end)
